package cn.saddyfire.pattern.flyweight;

import java.util.HashMap;

/**
 * @author Dee
 * @date 2024/2/4
 * <p>Description:工厂类, 将该类设计为单例模式
 */
public class BoxFactory {

    private HashMap<String, AbastractBox> map;

    private BoxFactory() {
        map = new HashMap<>();
        map.put("I", new IBox());
        map.put("L", new LBox());
        map.put("O", new OBox());
    }
    //提供方法获取该工厂类对象
    public static BoxFactory getInstance() {
        return FACTORY;
    }
    private static BoxFactory FACTORY = new BoxFactory();
    //根据名称获取图形对象
    public AbastractBox getShape(String name) {
        return map.get(name);
    }
}
